package com.ms.game.itembox.container;

import java.math.BigDecimal;

import com.ms.game.itembox.Item;
import com.ms.game.itembox.ItemBox;
import com.ms.game.itembox.ItemChangeWay;
import com.ms.player.Player;
import com.ms.player.PlayerUserType;
import com.ms.service.error.ErrorCode;
import com.ms.service.module.analysisgroup.AnalysisGroupProcessor;
import com.ms.service.module.zone.BasicZone;
import com.ms.service.module.zone.module.BasicZoneModule;
import com.xpec.c4.game.datamanager.BaseDataInfo;
import com.xpec.c4.game.datamanager.agent.money.ChangeCoinLister;
import com.xpec.c4.game.datamanager.agent.money.CoinType;
import com.xpec.c4.game.datamanager.agent.money.MoneyChangeParam;
import com.xpec.c4.game.datamanager.agent.money.MoneyChangeWay;
import com.xpec.c4.game.utility.GUID;
import com.xpec.c4.service.contexts.Contexts;
import com.xpec.c4.service.module.common.PlayerCommonInfoManager;

/**
 * C幣卡
 * @author TW16028
 *
 */
public class ItemGoldCoinCard extends ItemBasic{

	/**
	 * C幣
	 */
	private int goldCoin;
	
	
	public int getGoldCoin() {
		return goldCoin;
	}


	public void setGoldCoin(int goldCoin) {
		this.goldCoin = goldCoin;
	}

	
	
	@Override
	public int use(Player player, Item useItem, int useCount, GUID targetGuid, Object... object) {

		return 0;
	}


	@Override
	public int applyItemToDc(BasicZoneModule zoneModule, Player player, Item useItem, GUID orderId, Object... object) {
		MoneyChangeWay goldChangeWay = MoneyChangeWay.ADD_USE_GOLDCOIN_CARD;

		ChangeCoinLister coinLister = new ChangeCoinLister();
		if (goldCoin > 0) {
			coinLister.addCoin(CoinType.GOLD, new BigDecimal(goldCoin));
		}
		
		String callback = "updatePlayerMoneyItemToDcCallback";
		
		String moduleName = zoneModule.getModuleName();
		String zoneId = player.getZoneId();
		
		zoneModule.getPlayerDataAgent().updatePlayerMoneyToDC
		(
				orderId,
				player,
				coinLister,
				goldChangeWay,
				MoneyChangeParam.NO_JACKPOT,
				false,
				null,
				null,
				zoneModule,
				zoneId,
				zoneId,
				moduleName,
				moduleName,
				null,
				this,
				callback,
				player.getUserType(), //userObject[0]
				useItem.getCreateItemWay(), //userObject[1]
				useItem.getCreateGameType(), //userObject[2]
				useItem.getCreateHallType() //userObject[3]
		);
		
		return ErrorCode.SUCCESS;
	}

	public void updatePlayerMoneyItemToDcCallback(BaseDataInfo obj, Object... userObject) {
		MoneyChangeParam params = (MoneyChangeParam) obj.getData();
		GUID playerId = params.getPlayerId();
		GUID sessionId = PlayerCommonInfoManager.getInstance().getSessionByPlayerGuid(playerId);
		GUID accountID = PlayerCommonInfoManager.getInstance().getAccountIdByPlayerGuid(playerId);
		if(sessionId == null){
			return;
		}
		
		BasicZoneModule zoneModule = (BasicZoneModule)Contexts.getModule();
		BasicZone basicZone = zoneModule.getZone();
		//移除block list
		basicZone.removeBlockList(playerId, null);
		
		ItemBox.sendUseItemResponseToClient(sessionId, obj.getResultCode(), accountID, playerId);
		
		sendCoinCardDetailToAnalysis
		(
				obj.getResultCode(),
				(Integer)userObject[0],
				(ItemChangeWay)userObject[1],
				(String)userObject[2],
				(String)userObject[3]
		);
	}

	/**
	 * 送給C幣統計
	 */
	public void sendCoinCardDetailToAnalysis(int resultCode, int userType, ItemChangeWay createWay, String createGameType, String createHallType){
		if(resultCode == ErrorCode.SUCCESS && userType == PlayerUserType.PLAYER){
			
			//C幣卡使用細節
			AnalysisGroupProcessor.sendCoinCardDetailToAnalysis(createWay, createGameType, createHallType, goldCoin);
		}
	}

}
